name: easymacher-docker-heroku CD

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

#set environment variables
env:
  HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
  EASYMACHER_DB_ADDRESS: ${{''}}
  EASYMACHER_DB_PORT: ${{''}}
  APP_NAME: ${{ 'pocket_investor' }}

jobs:
  deploy:
    name: Deploy to Heroku
    runs-on: ubuntu-18.04
    steps:
      - uses: actions/checkout@v2
      - name: Set up JDK 11
        uses: actions/setup-java@v2
        with:
          java-version: '11'
          distribution: 'adopt'
      - name: Run mvn assembly without tests
        run: mvn clean install

      # Build Docker image
      - name: Docker build
        run: docker login --username=_ --password=$HEROKU_API_KEY registry.heroku.com

      # Push the Docker image to Heroku Container Registry
      - name: Publish
        run: |
          heroku container:push web -a $APP_NAME
          heroku container:release web -a $APP_NAME
      # Clone the repository
      - name: Checkout
        uses: actions/checkout@v2
